<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>出差图表</title>

<!-- 引入echarts.js-->
<script src="Scripts/echarts.js"></script>

<script type="text/javascript" src="Scripts/jquery.min.js"></script>
<!-- 导入主题js文件 -->
<script type="text/javascript" src="theme/infographic.js"></script>
<script type="text/javascript" src="theme/vintage.js"></script>
<script type="text/javascript" src="theme/green.js"></script>
<script type="text/javascript" src="theme/blue.js"></script>
<script type="text/javascript" src="theme/gray.js"></script>
<script type="text/javascript" src="theme/mint.js"></script>
<script type="text/javascript" src="theme/sakura.js"></script>
<script type="text/javascript" src="theme/macarons2.js"></script>
<script type="text/javascript">
	function getEchart(){
		$.ajax({
			url:"",
			type:"post",
			async : false, //同步执行 
			dataType:"json",
			
			success:function(result){
				if(result){
					/* options.legend.data = result.legend;  
					option.xAxis[0].data = result.category;   
					option.series[0].data = result.series[0].data;  */
					option.legend.data = result.legend;
					option.series[0].data = result.series;
					//console.log(result);
					//console.log(option.series[0].data);
					myChart.hideLoading();
					myChart.setOption(option);//更新图表
				}
			},
			error : function(errorMsg) {
				alert("不好意思，图表请求数据失败啦!");
				myChart.hideLoading();
			}
		});
	}
</script>
</head>
<body>
	<!-- 为ECharts准备一个具备大小（宽高）的Dom-->
	<div id="mainPie" style="height:500px;border:1px solid #ccc;padding:10px;"></div>
	
	<script type="text/javascript">
		var dou=document.getElementById("mainPie");
		//alert(dom);
		//通过内置对象的 init()函数 创建图表对象 (全局变量)
		var myChart = echarts.init(dom);//可传入第二个参数设置主图
		var app={};
		//全局变量option，json对象
		var option = {
				title : {
					text : '出差申请统计',
					subtext : '',
					x : 'center'
				},
				tooltip : {
					trigger : 'item',
					formatter : "{a} <br/>{b} : {c} ({d}%)"
				},
				legend : {
					orient : 'vartical',
					x : 'left',
					data : [],
				},
				toolbox : {
					show : true,
					feature : {
						mark : {
							show : true
						},
						dataView : {
							show : true,
							readOnly : false
						},
						restore : {
							show : true
						},
						saveAsImage : {
							show : true
						}
					}
				},
				calculable : true,
				series : [{
					name : '访问来源',
					type : 'pie',
					radius : '55%',
					center : ['50%','60%'],
					data : [],
					itemStyle : {
						emphasis : {
							shadowBlur : 10,
							shadowOffsetX : 0,
							shadowColor : 'rgba(0, 0, 0, 0.5)'
						}
					}
				}]
		};
		
		// 为echarts对象加载数据 
		myChart.setOption(option);
		myChart.hideLoading();
		getEchart();//aja后台交互    
		// alert("===");
		
	</script>
</body>
</html>